<?php

class Core_Backend_Component_Article_Controller_Helper extends Dcmp_Component_Controller {

    public function chooseArticleAction($title = '', $callback = '', $isself = '', $elementid = '', $selected = '', $sort = 'id', $dir = 'asc') {
        $this->getHistory()->record();
        $validator = new Kd_Validation_Validator();
        $validator->setTarget($this->getRequest()->getParameter('filter'));
        $collection = App::getModel('article/collection_content')
                        ->joinCategory()
                        ->joinAccount()
                        ->pagination(1, 50)
                        ->sortBy($sort, $dir);
        $collection->filterByStatus('published');
        if ($validator->isNotEmpty('title')) {
            $collection->filterByTitle($validator->getValue('title'));
        }
        if($validator->isNotEmpty('categoryname')){
            $collection->filterByCategoryName($validator->getValue('categoryname'));
        }
        if(!empty($selected)){
            $ids = explode(',', $selected);
            Kd_Util_Array::removeEmpty($ids);
            if(!empty($ids)){
                $collection->not()->contain('a.id', ':ids:i')->addParameter('ids', $ids);
            }
        }
        $collection->load();
        return $this->viewResult(
                array('list'=>$collection,
                      'element_id'=>$elementid,
                      'callback'=>$callback,
                      'selected'=>$selected,
                      'is_self'=>$isself,
                      'title'=>$title));
    }

}